﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace ChuyenDongVatLy
{
    
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D _background;

        GameMPN chuyendongthang;
        DaoDongDieuHoa daodongdieuhoa;
        ConLacDon conlacdon;
        
        ChuyenDongNemXien nemxien;
        MatPhangNghieng mpnghien;
        MPN2 mpn;

        MouseGame mouse;
        int numberSate = 7;
        int numberState2 = 0;
        bool isBegin = false;
      
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.PreferredBackBufferHeight = 650;
            graphics.PreferredBackBufferWidth = 800;
        }
        protected override void Initialize()
        {       
            if (isBegin==false)
            {
                InitializeGame(); 
            }
                                          
            base.Initialize();
        }
        public void InitializeGame()
        {
            chuyendongthang = new GameMPN(this);
            daodongdieuhoa = new DaoDongDieuHoa(this);
            conlacdon = new ConLacDon(this);
            nemxien = new ChuyenDongNemXien(this);
            mpnghien = new MatPhangNghieng(this);
            mouse = new MouseGame(this);           
            mpn = new MPN2(this);


        }
        protected override void LoadContent()
        {          
            spriteBatch = new SpriteBatch(GraphicsDevice);
            _background = Content.Load<Texture2D>("nen");
            chuyendongthang.LoadContent(Content);
            daodongdieuhoa.LoadContent(Content);
            conlacdon.LoadContent(Content);
            
            nemxien.LoadContent(Content);
            mpnghien.LoadContent(Content);
            mouse.LoadContent(Content);          
            mpn.LoadContent(Content);
        }       
        protected override void UnloadContent()
        {          
        }   
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            // TODO: Add your update logic here
           
                switch (numberSate)
                {
                    case 0:
                        break;
                    case 1:                        
                        this.chuyendongthang.Update(gameTime);
                        numberState2 = 1;
                        break;
                    case 2:
                        this.daodongdieuhoa.Update(gameTime);
                        numberState2 = 1;
                        break;
                    case 3:
                        this.conlacdon.Update(gameTime);
                        numberState2 = 1;
                        break;
                    case 4:
                        this.mpnghien.Update(gameTime);
                        numberState2 = 1;
                        break;
                    case 5:
                        this.nemxien.Update(gameTime);
                        numberState2 = 1;
                        break;
                    case 6:
                        this.mpn.Update(gameTime);
                        numberState2 = 1;
                        break;
                    case 7:                       
                        numberState2 = 0;
                        TimeGame._gameTime = 0;
                        break;
                    default:
                        break;
                }
                mouse.Update(gameTime);
                                                     
            base.Update(gameTime);
        }       
        protected override void Draw(GameTime gameTime)
        {
            SpriteFont font= Content.Load<SpriteFont>("font");
            GraphicsDevice.Clear(Color.SteelBlue);
            
            // TODO: Add your drawing code here
            spriteBatch.Begin();
            
            spriteBatch.Draw(_background, new Rectangle(0,0,800,700), Color.White);
           
            if (isBegin==false)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.D1))
                {
                    numberSate = 2; isBegin = true;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.D2))
                {
                    numberSate = 3; isBegin = true;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.D3))
                {
                    numberSate = 5; isBegin = true;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.D4))
                {
                    numberSate = 4; isBegin = true;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.D5))
                {
                    numberSate = 6; isBegin = true;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.D6))
                {
                    numberSate = 1; isBegin = true;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                {
                    numberSate = 7; isBegin = true;
                }
                
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                numberSate = 7;
                isBegin = false;
                TimeGame._ShowForm = true;
            }
            
           
                if (numberSate == 1)
                {
                    chuyendongthang.Draw(spriteBatch);
                }
                else if (numberSate == 2)
                {
                    daodongdieuhoa.Draw(spriteBatch);
                }
                else if (numberSate == 3)
                {
                    conlacdon.Draw(spriteBatch);
                }
                else if (numberSate==4)
                {
                    mpnghien.Draw(spriteBatch);
                }
                else if (numberSate==5)
                {
                    nemxien.Draw(spriteBatch);
                }
                else if (numberSate==6)
                {
                    mpn.Draw(spriteBatch);
                }
            
            else if(numberSate==7)
            {
                spriteBatch.DrawString(font, "Phim 1 : Dao Dong Dieu Hoa \n\nPhim 2 : Con Lac Don\n\nPhim 3 : Nem Xien\n\nPhim 4 : Thiet Ke MPN\n\nPhim 5 : Mat Phang Nghieng\n\nPhim 6 : Game Mini", new Vector2(250, 200), Color.Yellow);
               
            }                             
                    mouse.Draw(spriteBatch);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
